package com.andy.config;

import freemarker.template.TemplateExceptionHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.IOException;

@Configuration
public class FreeMarkerConfig {

    @Value("${workspacePath}")
    private String workspacePath;

    @Bean
    public freemarker.template.Configuration freemarkerTemplateConfiguration(){
        freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_28);
        try {

            cfg.setDirectoryForTemplateLoading(new File(workspacePath+"src\\main\\java\\com\\andy\\config\\ftl"));
            //cfg.setDirectoryForTemplateLoading(new File("src/main/java/com/andy/config/ftl"));
            cfg.setDefaultEncoding("UTF-8");
            cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
            cfg.setLogTemplateExceptions(false);
            cfg.setWrapUncheckedExceptions(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return cfg;
    }

}
